package com.crm.dao;



import java.util.List;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;

import com.crm.dao.core.BaseDao;
import com.crm.pojo.Contact;
import com.crm.pojo.User;

public class ContactDao extends BaseDao<Contact,String>{

	public List<Contact> findCompany(String q) {
		Criterion re = Restrictions.like("name", q, MatchMode.ANYWHERE);
		Criterion re2 = Restrictions.isNull("companyname");
		
		return find(re,re2);
	}

	public List<Contact> findByUser(User user) {
		Criterion re = Restrictions.eq("view", "a");
		Criterion re1 = Restrictions.like("view", user.getId(), MatchMode.ANYWHERE);
		Criterion re2 = Restrictions.like("view", user.getGroup().getId(), MatchMode.ANYWHERE);
		return findByOr(re,re1,re2);
	
	}
	
	
	
}
